<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>API Reference &#8212; Switchyard 2017.01.5 documentation</title>
    
    <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '2017.01.5',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Release notes" href="release_notes.html" />
    <link rel="prev" title="Installing Switchyard" href="installation.html" /> 
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="release_notes.html" title="Release notes"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="installation.html" title="Installing Switchyard"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">Switchyard 2017.01.5 documentation</a> &#187;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">API Reference</a><ul>
<li><a class="reference internal" href="#net-object-reference">Net object reference</a></li>
<li><a class="reference internal" href="#interface-and-interfacetype-reference">Interface and InterfaceType reference</a></li>
<li><a class="reference internal" href="#ethernet-and-ip-addresses">Ethernet and IP addresses</a></li>
<li><a class="reference internal" href="#packet-parsing-and-construction-reference">Packet parsing and construction reference</a><ul>
<li><a class="reference internal" href="#header-classes">Header classes</a></li>
<li><a class="reference internal" href="#ethernet-header">Ethernet header</a></li>
<li><a class="reference internal" href="#arp-address-resolution-protocol-header">ARP (address resolution protocol) header</a></li>
<li><a class="reference internal" href="#ip-version-4-header">IP version 4 header</a></li>
<li><a class="reference internal" href="#ip-version-6-header">IP version 6 header</a></li>
<li><a class="reference internal" href="#udp-user-datagram-protocol-header">UDP (user datagram protocol) header</a></li>
<li><a class="reference internal" href="#tcp-transmission-control-protocol-header">TCP (transmission control protocol) header</a></li>
<li><a class="reference internal" href="#icmp-internet-control-message-protocol-header-v4">ICMP (Internet control message protocol) header (v4)</a></li>
<li><a class="reference internal" href="#icmp-internet-control-message-protocol-header-v6">ICMP (Internet control message protocol) header (v6)</a></li>
</ul>
</li>
<li><a class="reference internal" href="#test-scenario-creation">Test scenario creation</a></li>
<li><a class="reference internal" href="#application-layer">Application-layer</a></li>
<li><a class="reference internal" href="#utility-functions">Utility functions</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="installation.html"
                        title="previous chapter">Installing Switchyard</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="release_notes.html"
                        title="next chapter">Release notes</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/reference.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="api-reference">
<span id="apiref"></span><h1>API Reference<a class="headerlink" href="#api-reference" title="Permalink to this headline">¶</a></h1>
<p>Before getting into all the details, it is important to note that all the below API features can be imported through the module <code class="docutils literal"><span class="pre">switchyard.lib.userlib</span></code>.</p>
<span class="target" id="module-switchyard.lib.userlib"></span><p>This is a wrapper module to facilitate easy import of the various modules, functions, classes, and other items needed from the perspective of a user program in Switchyard.</p>
<p>Unless you are concerned about namespace pollution, importing all Switchyard symbols into your program can be done with the following:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">switchyard.lib.userlib</span> <span class="kn">import</span> <span class="o">*</span>
</pre></div>
</div>
<div class="section" id="net-object-reference">
<span id="netobj"></span><h2>Net object reference<a class="headerlink" href="#net-object-reference" title="Permalink to this headline">¶</a></h2>
<p>The <em>net</em> object is used for sending and receiving packets on network interfaces/ports.  The API documentation below is for a base class that defines the various methods on a net object; there are two classes that derive from this base class which help to implement Switchyard&#8217;s test mode and Switchyard&#8217;s live network mode.</p>
<dl class="class">
<dt id="switchyard.llnetbase.LLNetBase">
<em class="property">class </em><code class="descclassname">switchyard.llnetbase.</code><code class="descname">LLNetBase</code><span class="sig-paren">(</span><em>name=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/llnetbase.html#LLNetBase"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.llnetbase.LLNetBase" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for the low-level networking library in Python.
&#8220;net&#8221; objects are constructed from classes derived from this
class.</p>
<p>An object of this class is passed into the main function of a user&#8217;s
Switchyard program.  Using methods on this object, a user can send/receive
packets and query the device for what interfaces are available and how
they are configured.</p>
<dl class="method">
<dt id="switchyard.llnetbase.LLNetBase.interface_by_ipaddr">
<code class="descname">interface_by_ipaddr</code><span class="sig-paren">(</span><em>ipaddr</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/llnetbase.html#LLNetBase.interface_by_ipaddr"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.llnetbase.LLNetBase.interface_by_ipaddr" title="Permalink to this definition">¶</a></dt>
<dd><p>Given an IP address, return the interface that &#8216;owns&#8217; this address</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.llnetbase.LLNetBase.interface_by_macaddr">
<code class="descname">interface_by_macaddr</code><span class="sig-paren">(</span><em>macaddr</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/llnetbase.html#LLNetBase.interface_by_macaddr"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.llnetbase.LLNetBase.interface_by_macaddr" title="Permalink to this definition">¶</a></dt>
<dd><p>Given a MAC address, return the interface that &#8216;owns&#8217; this address</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.llnetbase.LLNetBase.interface_by_name">
<code class="descname">interface_by_name</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/llnetbase.html#LLNetBase.interface_by_name"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.llnetbase.LLNetBase.interface_by_name" title="Permalink to this definition">¶</a></dt>
<dd><p>Given a device name, return the corresponding interface object</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.llnetbase.LLNetBase.interfaces">
<code class="descname">interfaces</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/llnetbase.html#LLNetBase.interfaces"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.llnetbase.LLNetBase.interfaces" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a list of interfaces incident on this node/router.
Each item in the list is an Interface object, each of which includes
name, ethaddr, ipaddr, and netmask attributes.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.llnetbase.LLNetBase.port_by_ipaddr">
<code class="descname">port_by_ipaddr</code><span class="sig-paren">(</span><em>ipaddr</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/llnetbase.html#LLNetBase.port_by_ipaddr"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.llnetbase.LLNetBase.port_by_ipaddr" title="Permalink to this definition">¶</a></dt>
<dd><p>Alias for interface_by_ipaddr</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.llnetbase.LLNetBase.port_by_macaddr">
<code class="descname">port_by_macaddr</code><span class="sig-paren">(</span><em>macaddr</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/llnetbase.html#LLNetBase.port_by_macaddr"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.llnetbase.LLNetBase.port_by_macaddr" title="Permalink to this definition">¶</a></dt>
<dd><p>Alias for interface_by_macaddr</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.llnetbase.LLNetBase.port_by_name">
<code class="descname">port_by_name</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/llnetbase.html#LLNetBase.port_by_name"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.llnetbase.LLNetBase.port_by_name" title="Permalink to this definition">¶</a></dt>
<dd><p>Alias for interface_by_name</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.llnetbase.LLNetBase.ports">
<code class="descname">ports</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/llnetbase.html#LLNetBase.ports"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.llnetbase.LLNetBase.ports" title="Permalink to this definition">¶</a></dt>
<dd><p>Alias for interfaces() method.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.llnetbase.LLNetBase.recv_packet">
<code class="descname">recv_packet</code><span class="sig-paren">(</span><em>timeout=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/llnetbase.html#LLNetBase.recv_packet"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.llnetbase.LLNetBase.recv_packet" title="Permalink to this definition">¶</a></dt>
<dd><p>Receive a packet on any port/interface.
If a non-None timeout is given, the method will block for up
to timeout seconds.  If no packet is available, the exception
NoPackets will be raised.  If the Switchyard framework is being
shut down, the Shutdown exception will be raised.
If a packet is available, the ReceivedPacket named tuple 
(timestamp, input_port, packet) will be returned.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.llnetbase.LLNetBase.send_packet">
<code class="descname">send_packet</code><span class="sig-paren">(</span><em>output_port</em>, <em>packet</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/llnetbase.html#LLNetBase.send_packet"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.llnetbase.LLNetBase.send_packet" title="Permalink to this definition">¶</a></dt>
<dd><p>Send a packet out the given output port/interface.  
Returns None.</p>
</dd></dl>

<dl class="attribute">
<dt id="switchyard.llnetbase.LLNetBase.testmode">
<code class="descname">testmode</code><a class="headerlink" href="#switchyard.llnetbase.LLNetBase.testmode" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns True if running in test mode and False if running in
live/real mode.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="interface-and-interfacetype-reference">
<span id="intf-detail"></span><h2>Interface and InterfaceType reference<a class="headerlink" href="#interface-and-interfacetype-reference" title="Permalink to this headline">¶</a></h2>
<p>The <code class="docutils literal"><span class="pre">InterfaceType</span></code> enumeration is referred to by the <code class="docutils literal"><span class="pre">Interface</span></code> class, which encapsulates information about a network interface/port.  The <code class="docutils literal"><span class="pre">InterfaceType</span></code> defines some basic options for types of interfaces:</p>
<dl class="class">
<dt id="switchyard.lib.interface.InterfaceType">
<em class="property">class </em><code class="descclassname">switchyard.lib.interface.</code><code class="descname">InterfaceType</code><a class="reference internal" href="_modules/switchyard/lib/interface.html#InterfaceType"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.interface.InterfaceType" title="Permalink to this definition">¶</a></dt>
<dd><p>An enumeration.</p>
<dl class="attribute">
<dt>
<code class="descname">Unknown=1</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">Loopback=2</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">Wired=3</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">Wireless=4</code></dt>
<dd></dd></dl>

</dd></dl>

<p>The <code class="docutils literal"><span class="pre">Interface</span></code> class is used to encapsulate information about a network interface:</p>
<dl class="class">
<dt id="switchyard.lib.interface.Interface">
<em class="property">class </em><code class="descclassname">switchyard.lib.interface.</code><code class="descname">Interface</code><span class="sig-paren">(</span><em>name</em>, <em>ethaddr</em>, <em>ipaddr=None</em>, <em>netmask=None</em>, <em>ifnum=None</em>, <em>iftype=&lt;InterfaceType.Unknown: 1&gt;</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/interface.html#Interface"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.interface.Interface" title="Permalink to this definition">¶</a></dt>
<dd><dl class="attribute">
<dt id="switchyard.lib.interface.Interface.ethaddr">
<code class="descname">ethaddr</code><a class="headerlink" href="#switchyard.lib.interface.Interface.ethaddr" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the Ethernet address associated with the interface</p>
</dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.interface.Interface.ifnum">
<code class="descname">ifnum</code><a class="headerlink" href="#switchyard.lib.interface.Interface.ifnum" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the interface number (integer) associated with the interface</p>
</dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.interface.Interface.iftype">
<code class="descname">iftype</code><a class="headerlink" href="#switchyard.lib.interface.Interface.iftype" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the type of the interface as a value from the InterfaceType enumeration.</p>
</dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.interface.Interface.ipaddr">
<code class="descname">ipaddr</code><a class="headerlink" href="#switchyard.lib.interface.Interface.ipaddr" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the IPv4 address associated with the interface</p>
</dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.interface.Interface.ipinterface">
<code class="descname">ipinterface</code><a class="headerlink" href="#switchyard.lib.interface.Interface.ipinterface" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the address assigned to this interface as an IPInterface object.  (see documentation for the built-in ipaddress module).</p>
</dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.interface.Interface.name">
<code class="descname">name</code><a class="headerlink" href="#switchyard.lib.interface.Interface.name" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the name of the interface</p>
</dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.interface.Interface.netmask">
<code class="descname">netmask</code><a class="headerlink" href="#switchyard.lib.interface.Interface.netmask" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the IPv4 subnet mask associated with the interface</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="ethernet-and-ip-addresses">
<span id="addresses"></span><h2>Ethernet and IP addresses<a class="headerlink" href="#ethernet-and-ip-addresses" title="Permalink to this headline">¶</a></h2>
<p>Switchyard uses the built-in <code class="docutils literal"><span class="pre">ipaddress</span></code> module to the extent possible.  Refer to the Python library documentation for details on the <code class="docutils literal"><span class="pre">IPv4Address</span></code> class and related classes.  As noted in the source code, the <code class="docutils literal"><span class="pre">EthAddr</span></code> class based on source code from the POX Openflow controller.</p>
<dl class="class">
<dt id="switchyard.lib.address.EthAddr">
<em class="property">class </em><code class="descclassname">switchyard.lib.address.</code><code class="descname">EthAddr</code><span class="sig-paren">(</span><em>addr=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/address.html#EthAddr"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.address.EthAddr" title="Permalink to this definition">¶</a></dt>
<dd><p>An Ethernet (MAC) address type.</p>
<dl class="method">
<dt id="switchyard.lib.address.EthAddr.isBridgeFiltered">
<code class="descname">isBridgeFiltered</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/address.html#EthAddr.isBridgeFiltered"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.address.EthAddr.isBridgeFiltered" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks if address is an IEEE 802.1D MAC Bridge Filtered MAC Group Address</p>
<p>This range is 01-80-C2-00-00-00 to 01-80-C2-00-00-0F. MAC frames that
have a destination MAC address within this range are not relayed by
bridges conforming to IEEE 802.1D</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.address.EthAddr.isGlobal">
<code class="descname">isGlobal</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/address.html#EthAddr.isGlobal"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.address.EthAddr.isGlobal" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns True if this is a globally unique (OUI enforced) address.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.address.EthAddr.isLocal">
<code class="descname">isLocal</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/address.html#EthAddr.isLocal"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.address.EthAddr.isLocal" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns True if this is a locally-administered (non-global) address.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.address.EthAddr.isMulticast">
<code class="descname">isMulticast</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/address.html#EthAddr.isMulticast"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.address.EthAddr.isMulticast" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns True if this is a multicast address.</p>
</dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.address.EthAddr.is_bridge_filtered">
<code class="descname">is_bridge_filtered</code><a class="headerlink" href="#switchyard.lib.address.EthAddr.is_bridge_filtered" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.address.EthAddr.is_global">
<code class="descname">is_global</code><a class="headerlink" href="#switchyard.lib.address.EthAddr.is_global" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.address.EthAddr.is_local">
<code class="descname">is_local</code><a class="headerlink" href="#switchyard.lib.address.EthAddr.is_local" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.address.EthAddr.is_multicast">
<code class="descname">is_multicast</code><a class="headerlink" href="#switchyard.lib.address.EthAddr.is_multicast" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.address.EthAddr.packed">
<code class="descname">packed</code><a class="headerlink" href="#switchyard.lib.address.EthAddr.packed" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.address.EthAddr.raw">
<code class="descname">raw</code><a class="headerlink" href="#switchyard.lib.address.EthAddr.raw" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the address as a 6-long bytes object.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.address.EthAddr.toRaw">
<code class="descname">toRaw</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/address.html#EthAddr.toRaw"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.address.EthAddr.toRaw" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="switchyard.lib.address.EthAddr.toStr">
<code class="descname">toStr</code><span class="sig-paren">(</span><em>separator=':'</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/address.html#EthAddr.toStr"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.address.EthAddr.toStr" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the address as string consisting of 12 hex chars separated
by separator.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.address.EthAddr.toTuple">
<code class="descname">toTuple</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/address.html#EthAddr.toTuple"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.address.EthAddr.toTuple" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a 6-entry long tuple where each entry is the numeric value
of the corresponding byte of the address.</p>
</dd></dl>

</dd></dl>

<p>There are two enumeration classes that hold special values for the IPv4 and IPv6 address families.  Note that since these classes derive from <code class="docutils literal"><span class="pre">enum</span></code>, you must use <code class="docutils literal"><span class="pre">name</span></code> to access the name attribute and <code class="docutils literal"><span class="pre">value</span></code> to access the value (address) attribute.</p>
<dl class="class">
<dt id="switchyard.lib.address.SpecialIPv4Addr">
<em class="property">class </em><code class="descclassname">switchyard.lib.address.</code><code class="descname">SpecialIPv4Addr</code><a class="reference internal" href="_modules/switchyard/lib/address.html#SpecialIPv4Addr"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.address.SpecialIPv4Addr" title="Permalink to this definition">¶</a></dt>
<dd><p>An enumeration.</p>
<dl class="attribute">
<dt>
<code class="descname">IP_ANY = ip_address(&quot;0.0.0.0&quot;)</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">IP_BROADCAST = ip_address(&quot;255.255.255.255&quot;)</code></dt>
<dd></dd></dl>

</dd></dl>

<dl class="class">
<dt id="switchyard.lib.address.SpecialIPv6Addr">
<em class="property">class </em><code class="descclassname">switchyard.lib.address.</code><code class="descname">SpecialIPv6Addr</code><a class="reference internal" href="_modules/switchyard/lib/address.html#SpecialIPv6Addr"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.address.SpecialIPv6Addr" title="Permalink to this definition">¶</a></dt>
<dd><p>An enumeration.</p>
<dl class="attribute">
<dt>
<code class="descname">UNDEFINED = ip_address('::')</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">ALL_NODES_LINK_LOCAL = ip_address('ff02::1')</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">ALL_ROUTERS_LINK_LOCAL = ip_address('ff02::2')</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">ALL_NODES_INTERFACE_LOCAL = ip_address('ff01::1')</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">ALL_ROUTERS_INTERFACE_LOCAL = ip_address('ff01::2')</code></dt>
<dd></dd></dl>

</dd></dl>

</div>
<div class="section" id="packet-parsing-and-construction-reference">
<span id="pktlib"></span><h2>Packet parsing and construction reference<a class="headerlink" href="#packet-parsing-and-construction-reference" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="switchyard.lib.packet.Packet">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.</code><code class="descname">Packet</code><span class="sig-paren">(</span><em>raw=None</em>, <em>first_header=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#Packet"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.Packet" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for packet headers.</p>
<p>The Packet class acts as a container for packet headers.  The
+ and += operators are defined for use with the Packet class
to add on headers (to the end of the packet).  Indexing can also
be done with Packet objects to access individual header objects.
Indexes may be integers (from 0 up to, but not including, the number
of packet headers), or indexes may also be packet header class names.
Exceptions are raised for invaliding indexing of either kind.</p>
<p>The optional raw parameter can accept a bytes object, which assumed
to be a serialized packet to be reconstructed.  The optional parameter
first_header indicates the first header of the packet to be reconstructed,
which defaults to Ethernet.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Packet</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">+=</span> <span class="n">Ethernet</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="go">&lt;switchyard.lib.packet.ethernet.Ethernet object at 0x10632bb08&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="p">[</span><span class="n">Ethernet</span><span class="p">]</span>
<span class="go">&lt;switchyard.lib.packet.ethernet.Ethernet object at 0x10632bb08&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">str</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
<span class="go">&#39;Ethernet 00:00:00:00:00:00-&gt;00:00:00:00:00:00 IP&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">str</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="go">&#39;Ethernet 00:00:00:00:00:00-&gt;00:00:00:00:00:00 IP&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">str</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="n">Ethernet</span><span class="p">])</span>
<span class="go">&#39;Ethernet 00:00:00:00:00:00-&gt;00:00:00:00:00:00 IP&#39;</span>
<span class="go">&gt;&gt;&gt;</span>
</pre></div>
</div>
<dl class="method">
<dt id="switchyard.lib.packet.Packet.add_header">
<code class="descname">add_header</code><span class="sig-paren">(</span><em>ph</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#Packet.add_header"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.Packet.add_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Add a PacketHeaderBase derived class object, or a raw bytes object
as the next &#8220;header&#8221; item in this packet.  Note that &#8216;header&#8217;
may be a slight misnomer since the last portion of a packet is
considered application payload and not a header per se.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.packet.Packet.add_payload">
<code class="descname">add_payload</code><span class="sig-paren">(</span><em>ph</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#Packet.add_payload"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.Packet.add_payload" title="Permalink to this definition">¶</a></dt>
<dd><p>Alias for add_header</p>
</dd></dl>

<dl class="staticmethod">
<dt id="switchyard.lib.packet.Packet.from_bytes">
<em class="property">static </em><code class="descname">from_bytes</code><span class="sig-paren">(</span><em>raw</em>, <em>first_header</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#Packet.from_bytes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.Packet.from_bytes" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a new packet by parsing the contents of a bytestring</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.packet.Packet.get_header">
<code class="descname">get_header</code><span class="sig-paren">(</span><em>hdrclass</em>, <em>returnval=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#Packet.get_header"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.Packet.get_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the first header object that is of
class hdrclass, or None if the header class isn&#8217;t
found.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.packet.Packet.get_header_by_name">
<code class="descname">get_header_by_name</code><span class="sig-paren">(</span><em>hdrname</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#Packet.get_header_by_name"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.Packet.get_header_by_name" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the header object that has the given (string) header
class name.  Returns None if no such header exists.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.packet.Packet.get_header_index">
<code class="descname">get_header_index</code><span class="sig-paren">(</span><em>hdrclass</em>, <em>startidx=0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#Packet.get_header_index"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.Packet.get_header_index" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the first index of the header class hdrclass
starting at startidx (default=0), or -1 if the
header class isn&#8217;t found in the list of headers.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.packet.Packet.has_header">
<code class="descname">has_header</code><span class="sig-paren">(</span><em>hdrclass</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#Packet.has_header"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.Packet.has_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if the packet has a header of the given hdrclass, 
False otherwise.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.packet.Packet.headers">
<code class="descname">headers</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#Packet.headers"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.Packet.headers" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a list of packet header names in this packet.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.packet.Packet.insert_header">
<code class="descname">insert_header</code><span class="sig-paren">(</span><em>idx</em>, <em>ph</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#Packet.insert_header"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.Packet.insert_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Insert a PacketHeaderBase-derived object at index idx the list of headers.
Any headers previously in the Packet from index idx:len(ph) are shifted to
make room for the new packet.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.packet.Packet.num_headers">
<code class="descname">num_headers</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#Packet.num_headers"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.Packet.num_headers" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the number of headers in the packet.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.packet.Packet.prepend_header">
<code class="descname">prepend_header</code><span class="sig-paren">(</span><em>ph</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#Packet.prepend_header"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.Packet.prepend_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Insert a PacketHeader object at the beginning of this packet
(i.e., as the first header of the packet).</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.packet.Packet.size">
<code class="descname">size</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#Packet.size"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.Packet.size" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the packed length of this header</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.packet.Packet.to_bytes">
<code class="descname">to_bytes</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#Packet.to_bytes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.Packet.to_bytes" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns serialized bytes object representing all headers/
payloads in this packet</p>
</dd></dl>

</dd></dl>

<p>To delete/remove a header, you can use the <code class="docutils literal"><span class="pre">del</span></code> operator as if the packet
object is a Python list:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">del</span> <span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="c1"># delete/remove first header in packet</span>
<span class="go">&gt;&gt;&gt;</span>
</pre></div>
</div>
<p>You can assign new header objects to a packet by integer index, but not
by packet header class index:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">Ethernet</span><span class="p">()</span> <span class="c1"># assign a new Ethernet header to index 0</span>
<span class="go">&gt;&gt;&gt;</span>
</pre></div>
</div>
<div class="section" id="header-classes">
<h3>Header classes<a class="headerlink" href="#header-classes" title="Permalink to this headline">¶</a></h3>
<p>In this section, detailed documentation for all packet header classes is given.  For each header class, there are three common <em>instance</em> methods that may be useful and which are <em>not</em> documented below for clarity. They are defined in the base class <code class="docutils literal"><span class="pre">PacketHeaderBase</span></code>.  Note that any new packet header classes that derive from <code class="docutils literal"><span class="pre">PacketHeaderBase</span></code> must implement these three methods.</p>
<dl class="class">
<dt id="switchyard.lib.packet.PacketHeaderBase">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.</code><code class="descname">PacketHeaderBase</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#PacketHeaderBase"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.PacketHeaderBase" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for packet headers.</p>
<dl class="method">
<dt id="switchyard.lib.packet.PacketHeaderBase.from_bytes">
<code class="descname">from_bytes</code><span class="sig-paren">(</span><em>raw</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#PacketHeaderBase.from_bytes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.PacketHeaderBase.from_bytes" title="Permalink to this definition">¶</a></dt>
<dd><p>Reconstruct the attributes of a header given the bytes object named raw.  The method returns any bytes that are <em>not</em> used to reconstruct a header.  An exception (typically a ValueError) is raised if there is some kind of problem deserializing the bytes object into packet header attributes.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.packet.PacketHeaderBase.size">
<code class="descname">size</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#PacketHeaderBase.size"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.PacketHeaderBase.size" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the number of bytes that the header would consist of when serialized to wire format</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.packet.PacketHeaderBase.to_bytes">
<code class="descname">to_bytes</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#PacketHeaderBase.to_bytes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.PacketHeaderBase.to_bytes" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a &#8216;packed&#8217; byte-level representation of this packet header.</p>
</dd></dl>

</dd></dl>

<p>There are also three common <em>class</em> methods that are used when creating a new packet header class (see <a class="reference internal" href="advanced_api.html#new-packet-header-types"><span class="std std-ref">Creating new packet header types</span></a>).</p>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.</code><code class="descname">PacketHeaderBase</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#PacketHeaderBase"><span class="viewcode-link">[source]</span></a></dt>
<dd><p>Base class for packet headers.</p>
<dl class="classmethod">
<dt id="switchyard.lib.packet.PacketHeaderBase.add_next_header_class">
<em class="property">classmethod </em><code class="descname">add_next_header_class</code><span class="sig-paren">(</span><em>attr</em>, <em>hdrcls</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#PacketHeaderBase.add_next_header_class"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.PacketHeaderBase.add_next_header_class" title="Permalink to this definition">¶</a></dt>
<dd><p>Add a new mapping between a next header type value and a Python
class that implements that header type.</p>
</dd></dl>

<dl class="classmethod">
<dt id="switchyard.lib.packet.PacketHeaderBase.set_next_header_class_key">
<em class="property">classmethod </em><code class="descname">set_next_header_class_key</code><span class="sig-paren">(</span><em>attr</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#PacketHeaderBase.set_next_header_class_key"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.PacketHeaderBase.set_next_header_class_key" title="Permalink to this definition">¶</a></dt>
<dd><p>Indicate which attribute is used to decide the type of packet
header that comes after this one.  For example, the IPv4
protocol attribute.</p>
</dd></dl>

<dl class="classmethod">
<dt id="switchyard.lib.packet.PacketHeaderBase.set_next_header_map">
<em class="property">classmethod </em><code class="descname">set_next_header_map</code><span class="sig-paren">(</span><em>mapdict</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/packet.html#PacketHeaderBase.set_next_header_map"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.PacketHeaderBase.set_next_header_map" title="Permalink to this definition">¶</a></dt>
<dd><p>(Re)initialize a dictionary that maps a &#8220;next header type&#8221; attribute
to a Python class that implements that header type.</p>
</dd></dl>

</dd></dl>

</div>
<hr class="docutils" />
<div class="section" id="ethernet-header">
<h3>Ethernet header<a class="headerlink" href="#ethernet-header" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="switchyard.lib.packet.Ethernet">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.</code><code class="descname">Ethernet</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/ethernet.html#Ethernet"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.Ethernet" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents an Ethernet header with fields src (source Ethernet address),
dst (destination Ethernet address), and ethertype (type of header to
come in the packet after the Ethernet header).  All valid ethertypes are
defined below.</p>
<dl class="attribute">
<dt id="switchyard.lib.packet.Ethernet.dst">
<code class="descname">dst</code><a class="headerlink" href="#switchyard.lib.packet.Ethernet.dst" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.Ethernet.ethertype">
<code class="descname">ethertype</code><a class="headerlink" href="#switchyard.lib.packet.Ethernet.ethertype" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.Ethernet.src">
<code class="descname">src</code><a class="headerlink" href="#switchyard.lib.packet.Ethernet.src" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="class">
<dt id="switchyard.lib.packet.common.EtherType">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.common.</code><code class="descname">EtherType</code><a class="reference internal" href="_modules/switchyard/lib/packet/common.html#EtherType"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.common.EtherType" title="Permalink to this definition">¶</a></dt>
<dd><p>An enumeration.</p>
<dl class="attribute">
<dt>
<code class="descname">IP = 0x0800</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">IPv4 = 0x0800</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">ARP = 0x0806</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">x8021Q = 0x8100</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">IPv6 = 0x86dd</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">SLOW = 0x8809</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">MPLS = 0x8847</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">x8021AD = 0x88a8</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">LLDP = 0x88cc</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">x8021AH = 0x88e7</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">IEEE8023 = 0x05dc</code></dt>
<dd></dd></dl>

<p>The EtherType class is derived from the built-in Python Enumerated
class type.  Note that some values start with &#8216;x&#8217; since they must
start with an alphabetic character to be valid in the enum.</p>
</dd></dl>

<p>By default, the Ethernet header addresses are all zeroes (&#8220;00:00:00:00:00:00&#8221;),
and the ethertype is IPv4.  Here is an example of creating an Ethernet header
and setting the header fields to non-default values:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">Ethernet</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">src</span> <span class="o">=</span> <span class="s2">&quot;de:ad:00:00:be:ef&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">dst</span> <span class="o">=</span> <span class="s2">&quot;ff:ff:ff:ff:ff:ff&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">ethertype</span> <span class="o">=</span> <span class="n">EtherType</span><span class="o">.</span><span class="n">ARP</span>
</pre></div>
</div>
<p>As with all packet header classes, keyword parameters can be used to initialize header attributes:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">Ethernet</span><span class="p">(</span><span class="n">src</span><span class="o">=</span><span class="s2">&quot;de:ad:00:00:be:ef&quot;</span><span class="p">,</span> <span class="n">dst</span><span class="o">=</span><span class="s2">&quot;ff:ff:ff:ff:ff:ff&quot;</span><span class="p">,</span> <span class="n">ethertype</span><span class="o">=</span><span class="n">EtherType</span><span class="o">.</span><span class="n">ARP</span><span class="p">)</span>
</pre></div>
</div>
</div>
<hr class="docutils" />
<div class="section" id="arp-address-resolution-protocol-header">
<h3>ARP (address resolution protocol) header<a class="headerlink" href="#arp-address-resolution-protocol-header" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="switchyard.lib.packet.Arp">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.</code><code class="descname">Arp</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/arp.html#Arp"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.Arp" title="Permalink to this definition">¶</a></dt>
<dd><dl class="attribute">
<dt id="switchyard.lib.packet.Arp.hardwaretype">
<code class="descname">hardwaretype</code><a class="headerlink" href="#switchyard.lib.packet.Arp.hardwaretype" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.Arp.operation">
<code class="descname">operation</code><a class="headerlink" href="#switchyard.lib.packet.Arp.operation" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.Arp.protocoltype">
<code class="descname">protocoltype</code><a class="headerlink" href="#switchyard.lib.packet.Arp.protocoltype" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.Arp.senderhwaddr">
<code class="descname">senderhwaddr</code><a class="headerlink" href="#switchyard.lib.packet.Arp.senderhwaddr" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.Arp.senderprotoaddr">
<code class="descname">senderprotoaddr</code><a class="headerlink" href="#switchyard.lib.packet.Arp.senderprotoaddr" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.Arp.targethwaddr">
<code class="descname">targethwaddr</code><a class="headerlink" href="#switchyard.lib.packet.Arp.targethwaddr" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.Arp.targetprotoaddr">
<code class="descname">targetprotoaddr</code><a class="headerlink" href="#switchyard.lib.packet.Arp.targetprotoaddr" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="class">
<dt id="switchyard.lib.packet.common.ArpOperation">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.common.</code><code class="descname">ArpOperation</code><a class="reference internal" href="_modules/switchyard/lib/packet/common.html#ArpOperation"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.common.ArpOperation" title="Permalink to this definition">¶</a></dt>
<dd><p>An enumeration.</p>
<dl class="attribute">
<dt>
<code class="descname">Request = 1</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">Reply = 2</code></dt>
<dd></dd></dl>

</dd></dl>

<p>The <code class="docutils literal"><span class="pre">Arp</span></code> class is used for constructing ARP (address resolution protocol)
requests and replies.  The <code class="docutils literal"><span class="pre">hardwaretype</span></code> property defaults to <code class="docutils literal"><span class="pre">Ethernet</span></code>,
so you don&#8217;t need to set that when an <code class="docutils literal"><span class="pre">Arp</span></code> object is instantiated.  The
operation can be set using the enumerated type <code class="docutils literal"><span class="pre">ArpOperation</span></code>, as indicated
above.  The remaining fields hold either <code class="docutils literal"><span class="pre">EthAddr</span></code> or <code class="docutils literal"><span class="pre">IPv4Address</span></code> objects,
and can be initialized using string representations of Ethernet or IPv4
addresses as appropriate.  Below is an example of creating an ARP request.
You can assume in the example that the senders Ethernet and IPv4
addresses are <code class="docutils literal"><span class="pre">srchw</span></code> and <code class="docutils literal"><span class="pre">srcip</span></code>, respectively.  You can also
assume that the IPv4 address for which we are requesting the Ethernet
address is <code class="docutils literal"><span class="pre">targetip</span></code>.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">ether</span> <span class="o">=</span> <span class="n">Ethernet</span><span class="p">()</span>
<span class="n">ether</span><span class="o">.</span><span class="n">src</span> <span class="o">=</span> <span class="n">srchw</span>
<span class="n">ether</span><span class="o">.</span><span class="n">dst</span> <span class="o">=</span> <span class="s1">&#39;ff:ff:ff:ff:ff:ff&#39;</span>
<span class="n">ether</span><span class="o">.</span><span class="n">ethertype</span> <span class="o">=</span> <span class="n">EtherType</span><span class="o">.</span><span class="n">ARP</span>
<span class="n">arp</span> <span class="o">=</span> <span class="n">Arp</span><span class="p">(</span><span class="n">operation</span><span class="o">=</span><span class="n">ArpOperation</span><span class="o">.</span><span class="n">Request</span><span class="p">,</span>
          <span class="n">senderhwaddr</span><span class="o">=</span><span class="n">srchw</span><span class="p">,</span>
          <span class="n">senderprotoaddr</span><span class="o">=</span><span class="n">srcip</span><span class="p">,</span>
          <span class="n">targethwaddr</span><span class="o">=</span><span class="s1">&#39;ff:ff:ff:ff:ff:ff&#39;</span><span class="p">,</span>
          <span class="n">targetprotoaddr</span><span class="o">=</span><span class="n">targetip</span><span class="p">)</span>
<span class="n">arppacket</span> <span class="o">=</span> <span class="n">ether</span> <span class="o">+</span> <span class="n">arp</span>
</pre></div>
</div>
</div>
<hr class="docutils" />
<div class="section" id="ip-version-4-header">
<h3>IP version 4 header<a class="headerlink" href="#ip-version-4-header" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="switchyard.lib.packet.IPv4">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.</code><code class="descname">IPv4</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/ipv4.html#IPv4"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.IPv4" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents an IP version 4 packet header.  All properties relate to
specific fields in the header and can be inspected and/or modified.</p>
<p>Note that the field named &#8220;hl&#8221; (&#8220;h-ell&#8221;) stands for &#8220;header length&#8221;.
It is the size of the header in 4-octet quantities.  It is a read-only
property (cannot be set).</p>
<p>Note also that some IPv4 header option classes are available in
Switchyard, but are currently undocumented.</p>
<dl class="attribute">
<dt id="switchyard.lib.packet.IPv4.dscp">
<code class="descname">dscp</code><a class="headerlink" href="#switchyard.lib.packet.IPv4.dscp" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.IPv4.dst">
<code class="descname">dst</code><a class="headerlink" href="#switchyard.lib.packet.IPv4.dst" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.IPv4.ecn">
<code class="descname">ecn</code><a class="headerlink" href="#switchyard.lib.packet.IPv4.ecn" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.IPv4.flags">
<code class="descname">flags</code><a class="headerlink" href="#switchyard.lib.packet.IPv4.flags" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.IPv4.fragment_offset">
<code class="descname">fragment_offset</code><a class="headerlink" href="#switchyard.lib.packet.IPv4.fragment_offset" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.IPv4.hl">
<code class="descname">hl</code><a class="headerlink" href="#switchyard.lib.packet.IPv4.hl" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.IPv4.ipid">
<code class="descname">ipid</code><a class="headerlink" href="#switchyard.lib.packet.IPv4.ipid" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.IPv4.options">
<code class="descname">options</code><a class="headerlink" href="#switchyard.lib.packet.IPv4.options" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.IPv4.protocol">
<code class="descname">protocol</code><a class="headerlink" href="#switchyard.lib.packet.IPv4.protocol" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.IPv4.src">
<code class="descname">src</code><a class="headerlink" href="#switchyard.lib.packet.IPv4.src" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.IPv4.tos">
<code class="descname">tos</code><a class="headerlink" href="#switchyard.lib.packet.IPv4.tos" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.IPv4.total_length">
<code class="descname">total_length</code><a class="headerlink" href="#switchyard.lib.packet.IPv4.total_length" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.IPv4.ttl">
<code class="descname">ttl</code><a class="headerlink" href="#switchyard.lib.packet.IPv4.ttl" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="class">
<dt id="switchyard.lib.packet.common.IPProtocol">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.common.</code><code class="descname">IPProtocol</code><a class="reference internal" href="_modules/switchyard/lib/packet/common.html#IPProtocol"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.common.IPProtocol" title="Permalink to this definition">¶</a></dt>
<dd><p>An enumeration.</p>
<dl class="attribute">
<dt>
<code class="descname">ICMP = 1</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">TCP = 6</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">UDP = 17</code></dt>
<dd></dd></dl>

<p>The IPProtocol class derives from the Python 3-builtin Enumerated
class type.  There are other protocol numbers defined.  See
<code class="xref py py-mod docutils literal"><span class="pre">switchyard.lib.packet.common</span></code> for all defined values.</p>
</dd></dl>

<p>A just-constructed IPv4 header defaults to having all zeroes for
the source and destination addresses (&#8216;0.0.0.0&#8217;) and the protocol
number defaults to ICMP.  An example of creating an IPv4 header
and setting various fields is shown below:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">ip</span> <span class="o">=</span> <span class="n">IPv4</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ip</span><span class="o">.</span><span class="n">srcip</span> <span class="o">=</span> <span class="s1">&#39;10.0.1.1&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ip</span><span class="o">.</span><span class="n">dstip</span> <span class="o">=</span> <span class="s1">&#39;10.0.2.42&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ip</span><span class="o">.</span><span class="n">protocol</span> <span class="o">=</span> <span class="n">IPProtocol</span><span class="o">.</span><span class="n">UDP</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ip</span><span class="o">.</span><span class="n">ttl</span> <span class="o">=</span> <span class="mi">64</span>
</pre></div>
</div>
</div>
<hr class="docutils" />
<div class="section" id="ip-version-6-header">
<h3>IP version 6 header<a class="headerlink" href="#ip-version-6-header" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="switchyard.lib.packet.IPv6">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.</code><code class="descname">IPv6</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/ipv6.html#IPv6"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.IPv6" title="Permalink to this definition">¶</a></dt>
<dd><dl class="attribute">
<dt id="switchyard.lib.packet.IPv6.dst">
<code class="descname">dst</code><a class="headerlink" href="#switchyard.lib.packet.IPv6.dst" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.IPv6.flowlabel">
<code class="descname">flowlabel</code><a class="headerlink" href="#switchyard.lib.packet.IPv6.flowlabel" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.IPv6.hopcount">
<code class="descname">hopcount</code><a class="headerlink" href="#switchyard.lib.packet.IPv6.hopcount" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.IPv6.nextheader">
<code class="descname">nextheader</code><a class="headerlink" href="#switchyard.lib.packet.IPv6.nextheader" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.IPv6.src">
<code class="descname">src</code><a class="headerlink" href="#switchyard.lib.packet.IPv6.src" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.IPv6.trafficclass">
<code class="descname">trafficclass</code><a class="headerlink" href="#switchyard.lib.packet.IPv6.trafficclass" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.IPv6.ttl">
<code class="descname">ttl</code><a class="headerlink" href="#switchyard.lib.packet.IPv6.ttl" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

</div>
<hr class="docutils" />
<div class="section" id="udp-user-datagram-protocol-header">
<h3>UDP (user datagram protocol) header<a class="headerlink" href="#udp-user-datagram-protocol-header" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="switchyard.lib.packet.UDP">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.</code><code class="descname">UDP</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/udp.html#UDP"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.UDP" title="Permalink to this definition">¶</a></dt>
<dd><p>The UDP header contains just source and destination port fields.</p>
<dl class="attribute">
<dt id="switchyard.lib.packet.UDP.dst">
<code class="descname">dst</code><a class="headerlink" href="#switchyard.lib.packet.UDP.dst" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.UDP.length">
<code class="descname">length</code><a class="headerlink" href="#switchyard.lib.packet.UDP.length" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.UDP.src">
<code class="descname">src</code><a class="headerlink" href="#switchyard.lib.packet.UDP.src" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<p>To construct a packet that includes an UDP header as well as some application
data, the same pattern of packet construction can be followed:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Ethernet</span><span class="p">()</span> <span class="o">+</span> <span class="n">IPv4</span><span class="p">(</span><span class="n">protocol</span><span class="o">=</span><span class="n">IPProtocol</span><span class="o">.</span><span class="n">UDP</span><span class="p">)</span> <span class="o">+</span> <span class="n">UDP</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="p">[</span><span class="n">UDP</span><span class="p">]</span><span class="o">.</span><span class="n">src</span> <span class="o">=</span> <span class="mi">4444</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="p">[</span><span class="n">UDP</span><span class="p">]</span><span class="o">.</span><span class="n">dst</span> <span class="o">=</span> <span class="mi">5555</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">+=</span> <span class="n">b</span><span class="s1">&#39;These are some application data bytes&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span> <span class="p">(</span><span class="n">p</span><span class="p">)</span>
<span class="go">Ethernet 00:00:00:00:00:00-&gt;00:00:00:00:00:00 IP | IPv4 0.0.0.0-&gt;0.0.0.0 UDP | UDP 4444-&gt;5555 | RawPacketContents (37 bytes) b&#39;These are &#39;...</span>
<span class="go">&gt;&gt;&gt;</span>
</pre></div>
</div>
<p>Note that we didn&#8217;t set the IP addresses or Ethernet addresses above, but
did set the IP protocol to correctly match the next header (UDP).  Adding
a payload to a packet is as simple as tacking on a Python <code class="docutils literal"><span class="pre">bytes</span></code> object.
You can also construct a <code class="docutils literal"><span class="pre">RawPacketContents</span></code> header, which is just a
packet header class that wraps a set of raw bytes.</p>
</div>
<hr class="docutils" />
<div class="section" id="tcp-transmission-control-protocol-header">
<h3>TCP (transmission control protocol) header<a class="headerlink" href="#tcp-transmission-control-protocol-header" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="switchyard.lib.packet.TCP">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.</code><code class="descname">TCP</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/tcp.html#TCP"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.TCP" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents a TCP header.  Includes properties to access/modify TCP
header fields.</p>
<dl class="attribute">
<dt id="switchyard.lib.packet.TCP.ACK">
<code class="descname">ACK</code><a class="headerlink" href="#switchyard.lib.packet.TCP.ACK" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.TCP.CWR">
<code class="descname">CWR</code><a class="headerlink" href="#switchyard.lib.packet.TCP.CWR" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.TCP.ECE">
<code class="descname">ECE</code><a class="headerlink" href="#switchyard.lib.packet.TCP.ECE" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.TCP.FIN">
<code class="descname">FIN</code><a class="headerlink" href="#switchyard.lib.packet.TCP.FIN" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.TCP.NS">
<code class="descname">NS</code><a class="headerlink" href="#switchyard.lib.packet.TCP.NS" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.TCP.PSH">
<code class="descname">PSH</code><a class="headerlink" href="#switchyard.lib.packet.TCP.PSH" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.TCP.RST">
<code class="descname">RST</code><a class="headerlink" href="#switchyard.lib.packet.TCP.RST" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.TCP.SYN">
<code class="descname">SYN</code><a class="headerlink" href="#switchyard.lib.packet.TCP.SYN" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.TCP.URG">
<code class="descname">URG</code><a class="headerlink" href="#switchyard.lib.packet.TCP.URG" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.TCP.ack">
<code class="descname">ack</code><a class="headerlink" href="#switchyard.lib.packet.TCP.ack" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.TCP.dst">
<code class="descname">dst</code><a class="headerlink" href="#switchyard.lib.packet.TCP.dst" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.TCP.flags">
<code class="descname">flags</code><a class="headerlink" href="#switchyard.lib.packet.TCP.flags" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.TCP.flagstr">
<code class="descname">flagstr</code><a class="headerlink" href="#switchyard.lib.packet.TCP.flagstr" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.TCP.offset">
<code class="descname">offset</code><a class="headerlink" href="#switchyard.lib.packet.TCP.offset" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.TCP.options">
<code class="descname">options</code><a class="headerlink" href="#switchyard.lib.packet.TCP.options" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.TCP.seq">
<code class="descname">seq</code><a class="headerlink" href="#switchyard.lib.packet.TCP.seq" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.TCP.src">
<code class="descname">src</code><a class="headerlink" href="#switchyard.lib.packet.TCP.src" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.TCP.urgent_pointer">
<code class="descname">urgent_pointer</code><a class="headerlink" href="#switchyard.lib.packet.TCP.urgent_pointer" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.TCP.window">
<code class="descname">window</code><a class="headerlink" href="#switchyard.lib.packet.TCP.window" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<p>Setting TCP header flags can be done by assigning 1 to any of the
mnemonic flag properties:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">TCP</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span><span class="o">.</span><span class="n">SYN</span> <span class="o">=</span> <span class="mi">1</span>
</pre></div>
</div>
<p>To check whether a flag has been set, you can simply inspect the
the flag value:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">if</span> <span class="n">t</span><span class="o">.</span><span class="n">SYN</span><span class="p">:</span>
<span class="gp">&gt;&gt;&gt; </span><span class="o">...</span>
</pre></div>
</div>
</div>
<hr class="docutils" />
<div class="section" id="icmp-internet-control-message-protocol-header-v4">
<h3>ICMP (Internet control message protocol) header (v4)<a class="headerlink" href="#icmp-internet-control-message-protocol-header-v4" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="switchyard.lib.packet.ICMP">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.</code><code class="descname">ICMP</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/icmp.html#ICMP"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.ICMP" title="Permalink to this definition">¶</a></dt>
<dd><p>A mother class for all ICMP message types.  It holds a reference
to another object that contains the specific ICMP data (icmpdata), 
given a particular ICMP type.  Just setting the icmptype causes the
data object to change (the change happens automatically when you
set the icmptype).  The icmpcode field will also change, but
it only changes to some valid code given the new icmptype.</p>
<p>Represents an ICMP packet header for IPv4.</p>
<dl class="attribute">
<dt id="switchyard.lib.packet.ICMP.icmpcode">
<code class="descname">icmpcode</code><a class="headerlink" href="#switchyard.lib.packet.ICMP.icmpcode" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.ICMP.icmpdata">
<code class="descname">icmpdata</code><a class="headerlink" href="#switchyard.lib.packet.ICMP.icmpdata" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.ICMP.icmptype">
<code class="descname">icmptype</code><a class="headerlink" href="#switchyard.lib.packet.ICMP.icmptype" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="class">
<dt id="switchyard.lib.packet.common.ICMPType">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.common.</code><code class="descname">ICMPType</code><a class="reference internal" href="_modules/switchyard/lib/packet/common.html#ICMPType"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.common.ICMPType" title="Permalink to this definition">¶</a></dt>
<dd><p>An enumeration.</p>
<dl class="attribute">
<dt>
<code class="descname">EchoReply = 0</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">DestinationUnreachable = 3</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">SourceQuench = 4</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">Redirect = 5</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">EchoRequest = 8</code></dt>
<dd></dd></dl>

<dl class="attribute">
<dt>
<code class="descname">TimeExceeded = 11</code></dt>
<dd></dd></dl>

</dd></dl>

<p>The icmptype and icmpcode header fields
determine the value stored in the icmpdata property.  When the icmptype
is set to a new value, the icmpdata field is <em>automatically</em> set to
the correct object.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">i</span> <span class="o">=</span> <span class="n">ICMP</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span> <span class="p">(</span><span class="n">i</span><span class="p">)</span>
<span class="go">ICMP EchoRequest 0 0 (0 data bytes)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span><span class="o">.</span><span class="n">icmptype</span> <span class="o">=</span> <span class="n">ICMPType</span><span class="o">.</span><span class="n">TimeExceeded</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span> <span class="p">(</span><span class="n">i</span><span class="p">)</span>
<span class="go">ICMP TimeExceeded:TTLExpired 0 bytes of raw payload (b&#39;&#39;) OrigDgramLen: 0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span><span class="o">.</span><span class="n">icmpcode</span>
<span class="go">&lt;ICMPCodeTimeExceeded.TTLExpired: 0&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span><span class="o">.</span><span class="n">icmpdata</span>
<span class="go">&lt;switchyard.lib.packet.icmp.ICMPTimeExceeded object at 0x10d3a3308&gt;</span>
</pre></div>
</div>
<p>Notice above that when the icmptype changes, other contents in the ICMP
header object change appropriately.</p>
<p>To access and/or modify the <em>payload</em> (i.e., data) that comes after the ICMP header, use <code class="docutils literal"><span class="pre">icmpdata.data</span></code>.  This object is a raw bytes object and can be accessed and or set.  For example, with many ICMP error messages, up to the first 28 bytes of the &#8220;dead&#8221; packet should be included, starting with the IPv4 header.  To do that, you must set the <code class="docutils literal"><span class="pre">icmpdata.data</span></code> attribute with the byte-level representation of the IP header data you want to include, as follows:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">i</span><span class="o">.</span><span class="n">icmpdata</span><span class="o">.</span><span class="n">data</span>
<span class="go">b&#39;&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span><span class="o">.</span><span class="n">icmpdata</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">pkt</span><span class="o">.</span><span class="n">to_bytes</span><span class="p">()[:</span><span class="mi">28</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span><span class="o">.</span><span class="n">icmpdata</span><span class="o">.</span><span class="n">origdgramlen</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">pkt</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span> <span class="p">(</span><span class="n">i</span><span class="p">)</span>
<span class="go">ICMP TimeExceeded:TTLExpired 28 bytes of raw payload (b&#39;E\x00\x00\x14\x00\x00\x00\x00\x00\x01&#39;) OrigDgramLen: 42</span>
<span class="go">&gt;&gt;&gt;</span>
</pre></div>
</div>
<p>In the above code segment, <code class="docutils literal"><span class="pre">pkt</span></code> should be a Packet object that just contains the IPv4 header and any subsequent headers and data.  It must <em>not</em> include an Ethernet header.  If you need to strip an Ethernet header, you can get its index (<code class="docutils literal"><span class="pre">pkt.get_header_index(Ethernet)</span></code>), then remove the header by index (<code class="docutils literal"><span class="pre">del</span> <span class="pre">pkt[index]</span></code>).</p>
<p>Notice that above, the <code class="docutils literal"><span class="pre">to_bytes</span></code> method returns the byte-level representation of the IP header we&#8217;re including as the payload.  The <code class="docutils literal"><span class="pre">to_bytes</span></code> method can be called on any packet header, or on an packet object (in which case <em>all</em> packet headers will be byte-serialized).</p>
<p>To set the icmpcode, a dictionary called <code class="docutils literal"><span class="pre">ICMPTypeCodeMap</span></code> is defined
in <code class="docutils literal"><span class="pre">switchyard.lib.packet</span></code>.  Keys in the dictionary are of type <code class="docutils literal"><span class="pre">ICMPType</span></code>, and values for each key is another enumerated type indicating the valid
codes for the given type.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">switchyard.lib.packet</span> <span class="k">import</span> <span class="o">*</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ICMPTypeCodeMap</span><span class="p">[</span><span class="n">ICMPType</span><span class="o">.</span><span class="n">DestinationUnreachable</span><span class="p">]</span>
<span class="go">&lt;enum &#39;DestinationUnreachable&#39;&gt;</span>
</pre></div>
</div>
<p>Just getting the dictionary value isn&#8217;t particularly helpful, but if you
coerce the enum to a list, you can see all valid values:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">ICMPTypeCodeMap</span><span class="p">[</span><span class="n">ICMPType</span><span class="o">.</span><span class="n">DestinationUnreachable</span><span class="p">])</span>
<span class="go">[ &lt;DestinationUnreachable.ProtocolUnreachable: 2&gt;,</span>
<span class="go">  &lt;DestinationUnreachable.SourceHostIsolated: 8&gt;,</span>
<span class="go">  &lt;DestinationUnreachable.FragmentationRequiredDFSet: 4&gt;,</span>
<span class="go">  &lt;DestinationUnreachable.HostUnreachable: 1&gt;,</span>
<span class="go">  &lt;DestinationUnreachable.DestinationNetworkUnknown: 6&gt;,</span>
<span class="go">  &lt;DestinationUnreachable.NetworkUnreachableForTOS: 11&gt;,</span>
<span class="go">  &lt;DestinationUnreachable.HostAdministrativelyProhibited: 10&gt;,</span>
<span class="go">  &lt;DestinationUnreachable.DestinationHostUnknown: 7&gt;,</span>
<span class="go">  &lt;DestinationUnreachable.HostPrecedenceViolation: 14&gt;,</span>
<span class="go">  &lt;DestinationUnreachable.PrecedenceCutoffInEffect: 15&gt;,</span>
<span class="go">  &lt;DestinationUnreachable.NetworkAdministrativelyProhibited: 9&gt;,</span>
<span class="go">  &lt;DestinationUnreachable.NetworkUnreachable: 0&gt;,</span>
<span class="go">  &lt;DestinationUnreachable.SourceRouteFailed: 5&gt;,</span>
<span class="go">  &lt;DestinationUnreachable.PortUnreachable: 3&gt;,</span>
<span class="go">  &lt;DestinationUnreachable.CommunicationAdministrativelyProhibited: 13&gt;,</span>
<span class="go">  &lt;DestinationUnreachable.HostUnreachableForTOS: 12&gt; ]</span>
</pre></div>
</div>
<p>Another example, but with the much simpler EchoRequest:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">ICMPTypeCodeMap</span><span class="p">[</span><span class="n">ICMPType</span><span class="o">.</span><span class="n">EchoRequest</span><span class="p">])</span>
<span class="go">[&lt;EchoRequest.EchoRequest: 0&gt;]</span>
</pre></div>
</div>
<p>If you try to set the icmpcode to an invalid value, an exception will be
raised:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>&gt;&gt;&gt; i = ICMP()
&gt;&gt;&gt; i.icmptype = ICMPType.DestinationUnreachable
&gt;&gt;&gt; i.icmpcode = 44
Traceback (most recent call last):
...
&gt;&gt;&gt;
</pre></div>
</div>
<p>You can either (validly) set the code using an integer, or a valid enumerated
type value:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">i</span><span class="o">.</span><span class="n">icmpcode</span> <span class="o">=</span> <span class="mi">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
<span class="go">ICMP DestinationUnreachable:ProtocolUnreachable 0 bytes of raw payload (b&#39;&#39;) NextHopMTU: 0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span><span class="o">.</span><span class="n">icmpcode</span> <span class="o">=</span> <span class="n">ICMPTypeCodeMap</span><span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">icmptype</span><span class="p">]</span><span class="o">.</span><span class="n">HostUnreachable</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span> <span class="p">(</span><span class="n">i</span><span class="p">)</span>
<span class="go">ICMP DestinationUnreachable:HostUnreachable 0 bytes of raw payload (b&#39;&#39;) NextHopMTU: 0</span>
</pre></div>
</div>
<p>Below are shown the ICMP data classes, as well as any properties that can
be inspected and/or modified on them.</p>
<dl class="class">
<dt id="switchyard.lib.packet.ICMPEchoReply">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.</code><code class="descname">ICMPEchoReply</code><a class="reference internal" href="_modules/switchyard/lib/packet/icmp.html#ICMPEchoReply"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.ICMPEchoReply" title="Permalink to this definition">¶</a></dt>
<dd><dl class="attribute">
<dt id="switchyard.lib.packet.ICMPEchoReply.data">
<code class="descname">data</code><a class="headerlink" href="#switchyard.lib.packet.ICMPEchoReply.data" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.ICMPEchoReply.identifier">
<code class="descname">identifier</code><a class="headerlink" href="#switchyard.lib.packet.ICMPEchoReply.identifier" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.ICMPEchoReply.sequence">
<code class="descname">sequence</code><a class="headerlink" href="#switchyard.lib.packet.ICMPEchoReply.sequence" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="class">
<dt id="switchyard.lib.packet.ICMPDestinationUnreachable">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.</code><code class="descname">ICMPDestinationUnreachable</code><a class="reference internal" href="_modules/switchyard/lib/packet/icmp.html#ICMPDestinationUnreachable"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.ICMPDestinationUnreachable" title="Permalink to this definition">¶</a></dt>
<dd><dl class="attribute">
<dt id="switchyard.lib.packet.ICMPDestinationUnreachable.data">
<code class="descname">data</code><a class="headerlink" href="#switchyard.lib.packet.ICMPDestinationUnreachable.data" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.ICMPDestinationUnreachable.nexthopmtu">
<code class="descname">nexthopmtu</code><a class="headerlink" href="#switchyard.lib.packet.ICMPDestinationUnreachable.nexthopmtu" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.ICMPDestinationUnreachable.origdgramlen">
<code class="descname">origdgramlen</code><a class="headerlink" href="#switchyard.lib.packet.ICMPDestinationUnreachable.origdgramlen" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="class">
<dt id="switchyard.lib.packet.ICMPSourceQuench">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.</code><code class="descname">ICMPSourceQuench</code><a class="reference internal" href="_modules/switchyard/lib/packet/icmp.html#ICMPSourceQuench"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.ICMPSourceQuench" title="Permalink to this definition">¶</a></dt>
<dd><dl class="attribute">
<dt id="switchyard.lib.packet.ICMPSourceQuench.data">
<code class="descname">data</code><a class="headerlink" href="#switchyard.lib.packet.ICMPSourceQuench.data" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="class">
<dt id="switchyard.lib.packet.ICMPRedirect">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.</code><code class="descname">ICMPRedirect</code><a class="reference internal" href="_modules/switchyard/lib/packet/icmp.html#ICMPRedirect"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.ICMPRedirect" title="Permalink to this definition">¶</a></dt>
<dd><dl class="attribute">
<dt id="switchyard.lib.packet.ICMPRedirect.data">
<code class="descname">data</code><a class="headerlink" href="#switchyard.lib.packet.ICMPRedirect.data" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.ICMPRedirect.redirectto">
<code class="descname">redirectto</code><a class="headerlink" href="#switchyard.lib.packet.ICMPRedirect.redirectto" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="class">
<dt id="switchyard.lib.packet.ICMPEchoRequest">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.</code><code class="descname">ICMPEchoRequest</code><a class="reference internal" href="_modules/switchyard/lib/packet/icmp.html#ICMPEchoRequest"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.ICMPEchoRequest" title="Permalink to this definition">¶</a></dt>
<dd><dl class="attribute">
<dt id="switchyard.lib.packet.ICMPEchoRequest.data">
<code class="descname">data</code><a class="headerlink" href="#switchyard.lib.packet.ICMPEchoRequest.data" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.ICMPEchoRequest.identifier">
<code class="descname">identifier</code><a class="headerlink" href="#switchyard.lib.packet.ICMPEchoRequest.identifier" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.ICMPEchoRequest.sequence">
<code class="descname">sequence</code><a class="headerlink" href="#switchyard.lib.packet.ICMPEchoRequest.sequence" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="class">
<dt id="switchyard.lib.packet.ICMPTimeExceeded">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.</code><code class="descname">ICMPTimeExceeded</code><a class="reference internal" href="_modules/switchyard/lib/packet/icmp.html#ICMPTimeExceeded"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.ICMPTimeExceeded" title="Permalink to this definition">¶</a></dt>
<dd><dl class="attribute">
<dt id="switchyard.lib.packet.ICMPTimeExceeded.data">
<code class="descname">data</code><a class="headerlink" href="#switchyard.lib.packet.ICMPTimeExceeded.data" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.ICMPTimeExceeded.origdgramlen">
<code class="descname">origdgramlen</code><a class="headerlink" href="#switchyard.lib.packet.ICMPTimeExceeded.origdgramlen" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

</div>
<div class="section" id="icmp-internet-control-message-protocol-header-v6">
<h3>ICMP (Internet control message protocol) header (v6)<a class="headerlink" href="#icmp-internet-control-message-protocol-header-v6" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="switchyard.lib.packet.ICMPv6">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.</code><code class="descname">ICMPv6</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/icmpv6.html#ICMPv6"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.ICMPv6" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents an ICMPv6 packet header.</p>
</dd></dl>

<p>Additional ICMPv6 headers to support the Network Discovery Protocol, [RFC4861](<a class="reference external" href="http://tools.ietf.org/html/rfc4861">http://tools.ietf.org/html/rfc4861</a>) are also available in Switchyard:</p>
<blockquote>
<div><ul class="simple">
<li>ICMPv6NeighborSolicitation</li>
<li>ICMPv6NeighborAdvertisement</li>
<li>ICMPv6RedirectMessage</li>
</ul>
</div></blockquote>
<p>To create an ICMPv6 packet an instance of type <code class="docutils literal"><span class="pre">ICMPv6</span></code> can be created.  You will want (and need) to set its <code class="docutils literal"><span class="pre">icmptype</span></code> appropriately, too.  For example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">icmpv6</span> <span class="o">=</span> <span class="n">ICMPv6</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">icmp</span><span class="o">.</span><span class="n">icmptype</span> <span class="o">=</span> <span class="n">ICMPv6Type</span><span class="o">.</span><span class="n">RedirectMessage</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">## OR Directly when initializing the ICMPv6 header</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># icmpv6 = ICMPv6(icmptype=ICMPv6Type.RedirectMessage)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">r</span> <span class="o">=</span> <span class="n">ICMPv6RedirectMessage</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># or r = icmpv6.icmpdata if already assigned to ICMPv6 object</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">r</span><span class="o">.</span><span class="n">targetaddr</span> <span class="o">=</span> <span class="n">IPv6Address</span><span class="p">(</span> <span class="s2">&quot;::0&quot;</span> <span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">r</span><span class="o">.</span><span class="n">options</span><span class="o">.</span><span class="n">append</span><span class="p">(</span> <span class="n">ICMPv6OptionRedirectedHeader</span><span class="p">(</span> <span class="n">redirected_packet</span><span class="o">=</span><span class="n">p</span> <span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">r</span><span class="o">.</span><span class="n">options</span><span class="o">.</span><span class="n">append</span><span class="p">(</span> <span class="n">ICMPv6OptionTargetLinkLayerAddress</span><span class="p">(</span> <span class="n">address</span><span class="o">=</span><span class="s2">&quot;00:00:00:00:00:00&quot;</span> <span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">icmpv6</span><span class="o">.</span><span class="n">icmpdata</span> <span class="o">=</span> <span class="n">r</span>
</pre></div>
</div>
<p>There are several ICMPv6 options which can be attached to these:</p>
<blockquote>
<div><ul class="simple">
<li>ICMPv6OptionSourceLinkLayerAddress</li>
<li>ICMPv6OptionTargetLinkLayerAddress</li>
<li>ICMPv6OptionRedirectedHeader</li>
</ul>
</div></blockquote>
<dl class="class">
<dt id="switchyard.lib.packet.ICMPv6NeighborSolicitation">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.</code><code class="descname">ICMPv6NeighborSolicitation</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/icmpv6.html#ICMPv6NeighborSolicitation"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.ICMPv6NeighborSolicitation" title="Permalink to this definition">¶</a></dt>
<dd><dl class="attribute">
<dt id="switchyard.lib.packet.ICMPv6NeighborSolicitation.data">
<code class="descname">data</code><a class="headerlink" href="#switchyard.lib.packet.ICMPv6NeighborSolicitation.data" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.ICMPv6NeighborSolicitation.options">
<code class="descname">options</code><a class="headerlink" href="#switchyard.lib.packet.ICMPv6NeighborSolicitation.options" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.ICMPv6NeighborSolicitation.targetaddr">
<code class="descname">targetaddr</code><a class="headerlink" href="#switchyard.lib.packet.ICMPv6NeighborSolicitation.targetaddr" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="class">
<dt id="switchyard.lib.packet.ICMPv6NeighborAdvertisement">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.</code><code class="descname">ICMPv6NeighborAdvertisement</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/icmpv6.html#ICMPv6NeighborAdvertisement"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.ICMPv6NeighborAdvertisement" title="Permalink to this definition">¶</a></dt>
<dd><dl class="attribute">
<dt id="switchyard.lib.packet.ICMPv6NeighborAdvertisement.data">
<code class="descname">data</code><a class="headerlink" href="#switchyard.lib.packet.ICMPv6NeighborAdvertisement.data" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="switchyard.lib.packet.ICMPv6NeighborAdvertisement.get_rso_byte">
<code class="descname">get_rso_byte</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/icmpv6.html#ICMPv6NeighborAdvertisement.get_rso_byte"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.ICMPv6NeighborAdvertisement.get_rso_byte" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="switchyard.lib.packet.ICMPv6NeighborAdvertisement.get_rso_str">
<code class="descname">get_rso_str</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/icmpv6.html#ICMPv6NeighborAdvertisement.get_rso_str"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.ICMPv6NeighborAdvertisement.get_rso_str" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.ICMPv6NeighborAdvertisement.options">
<code class="descname">options</code><a class="headerlink" href="#switchyard.lib.packet.ICMPv6NeighborAdvertisement.options" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.ICMPv6NeighborAdvertisement.overrideflag">
<code class="descname">overrideflag</code><a class="headerlink" href="#switchyard.lib.packet.ICMPv6NeighborAdvertisement.overrideflag" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.ICMPv6NeighborAdvertisement.routerflag">
<code class="descname">routerflag</code><a class="headerlink" href="#switchyard.lib.packet.ICMPv6NeighborAdvertisement.routerflag" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.ICMPv6NeighborAdvertisement.solicitedflag">
<code class="descname">solicitedflag</code><a class="headerlink" href="#switchyard.lib.packet.ICMPv6NeighborAdvertisement.solicitedflag" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.ICMPv6NeighborAdvertisement.targetaddr">
<code class="descname">targetaddr</code><a class="headerlink" href="#switchyard.lib.packet.ICMPv6NeighborAdvertisement.targetaddr" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="class">
<dt id="switchyard.lib.packet.ICMPv6RedirectMessage">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.</code><code class="descname">ICMPv6RedirectMessage</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/icmpv6.html#ICMPv6RedirectMessage"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.ICMPv6RedirectMessage" title="Permalink to this definition">¶</a></dt>
<dd><dl class="attribute">
<dt id="switchyard.lib.packet.ICMPv6RedirectMessage.data">
<code class="descname">data</code><a class="headerlink" href="#switchyard.lib.packet.ICMPv6RedirectMessage.data" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.ICMPv6RedirectMessage.destinationaddr">
<code class="descname">destinationaddr</code><a class="headerlink" href="#switchyard.lib.packet.ICMPv6RedirectMessage.destinationaddr" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.ICMPv6RedirectMessage.options">
<code class="descname">options</code><a class="headerlink" href="#switchyard.lib.packet.ICMPv6RedirectMessage.options" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.packet.ICMPv6RedirectMessage.targetaddr">
<code class="descname">targetaddr</code><a class="headerlink" href="#switchyard.lib.packet.ICMPv6RedirectMessage.targetaddr" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="class">
<dt id="switchyard.lib.packet.icmpv6.ICMPv6Option">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.icmpv6.</code><code class="descname">ICMPv6Option</code><span class="sig-paren">(</span><em>optnum</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/icmpv6.html#ICMPv6Option"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.icmpv6.ICMPv6Option" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="class">
<dt id="switchyard.lib.packet.icmpv6.ICMPv6OptionSourceLinkLayerAddress">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.icmpv6.</code><code class="descname">ICMPv6OptionSourceLinkLayerAddress</code><span class="sig-paren">(</span><em>address=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/icmpv6.html#ICMPv6OptionSourceLinkLayerAddress"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.icmpv6.ICMPv6OptionSourceLinkLayerAddress" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="class">
<dt id="switchyard.lib.packet.icmpv6.ICMPv6OptionTargetLinkLayerAddress">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.icmpv6.</code><code class="descname">ICMPv6OptionTargetLinkLayerAddress</code><span class="sig-paren">(</span><em>address=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/icmpv6.html#ICMPv6OptionTargetLinkLayerAddress"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.icmpv6.ICMPv6OptionTargetLinkLayerAddress" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="class">
<dt id="switchyard.lib.packet.icmpv6.ICMPv6OptionRedirectedHeader">
<em class="property">class </em><code class="descclassname">switchyard.lib.packet.icmpv6.</code><code class="descname">ICMPv6OptionRedirectedHeader</code><span class="sig-paren">(</span><em>redirected_packet=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/packet/icmpv6.html#ICMPv6OptionRedirectedHeader"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.packet.icmpv6.ICMPv6OptionRedirectedHeader" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># need to add various ICMPv6 examples</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="test-scenario-creation">
<h2>Test scenario creation<a class="headerlink" href="#test-scenario-creation" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="switchyard.lib.testing.TestScenario">
<em class="property">class </em><code class="descclassname">switchyard.lib.testing.</code><code class="descname">TestScenario</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/testing.html#TestScenario"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.testing.TestScenario" title="Permalink to this definition">¶</a></dt>
<dd><p>Test scenario definition.  Given a list of packetio event objects,
generates input events and tests/verifies output events.</p>
<dl class="method">
<dt id="switchyard.lib.testing.TestScenario.add_file">
<code class="descname">add_file</code><span class="sig-paren">(</span><em>fname</em>, <em>text</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/testing.html#TestScenario.add_file"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.testing.TestScenario.add_file" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="switchyard.lib.testing.TestScenario.add_interface">
<code class="descname">add_interface</code><span class="sig-paren">(</span><em>interface_name</em>, <em>macaddr</em>, <em>ipaddr=None</em>, <em>netmask=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/testing.html#TestScenario.add_interface"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.testing.TestScenario.add_interface" title="Permalink to this definition">¶</a></dt>
<dd><p>Add an interface to the test scenario.</p>
<p>(str, str/EthAddr, str/IPAddr, str/IPAddr) -&gt; None</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.testing.TestScenario.expect">
<code class="descname">expect</code><span class="sig-paren">(</span><em>event</em>, <em>description</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/testing.html#TestScenario.expect"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.testing.TestScenario.expect" title="Permalink to this definition">¶</a></dt>
<dd><p>Add a new event and description to the expected set of events
to occur for this test scenario.</p>
<p>(Event object, str) -&gt; None</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.testing.TestScenario.interfaces">
<code class="descname">interfaces</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/testing.html#TestScenario.interfaces"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.testing.TestScenario.interfaces" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.testing.TestScenario.name">
<code class="descname">name</code><a class="headerlink" href="#switchyard.lib.testing.TestScenario.name" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="switchyard.lib.testing.TestScenario.ports">
<code class="descname">ports</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/testing.html#TestScenario.ports"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.testing.TestScenario.ports" title="Permalink to this definition">¶</a></dt>
<dd><p>Alias for interfaces() method.</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="switchyard.lib.testing.PacketInputEvent">
<em class="property">class </em><code class="descclassname">switchyard.lib.testing.</code><code class="descname">PacketInputEvent</code><span class="sig-paren">(</span><em>device</em>, <em>packet</em>, <em>display=None</em>, <em>copyfromlastout=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/testing.html#PacketInputEvent"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.testing.PacketInputEvent" title="Permalink to this definition">¶</a></dt>
<dd><p>Test event that models a packet arriving at a router/switch
(e.g., a packet that we generate).</p>
<dl class="method">
<dt id="switchyard.lib.testing.PacketInputEvent.match">
<code class="descname">match</code><span class="sig-paren">(</span><em>evtype</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/testing.html#PacketInputEvent.match"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.testing.PacketInputEvent.match" title="Permalink to this definition">¶</a></dt>
<dd><p>Does event type match me?  PacketInputEvent currently ignores
any additional arguments.</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="switchyard.lib.testing.PacketInputTimeoutEvent">
<em class="property">class </em><code class="descclassname">switchyard.lib.testing.</code><code class="descname">PacketInputTimeoutEvent</code><span class="sig-paren">(</span><em>timeout</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/testing.html#PacketInputTimeoutEvent"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.testing.PacketInputTimeoutEvent" title="Permalink to this definition">¶</a></dt>
<dd><p>Test event that models a timeout when trying to receive
a packet.  No packet arrives, so the switchy app should
handle a NoPackets exception and continue</p>
<dl class="method">
<dt id="switchyard.lib.testing.PacketInputTimeoutEvent.match">
<code class="descname">match</code><span class="sig-paren">(</span><em>evtype</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/testing.html#PacketInputTimeoutEvent.match"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.testing.PacketInputTimeoutEvent.match" title="Permalink to this definition">¶</a></dt>
<dd><p>Does event type match me?  PacketInputEvent currently ignores
any additional arguments.</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="switchyard.lib.testing.PacketOutputEvent">
<em class="property">class </em><code class="descclassname">switchyard.lib.testing.</code><code class="descname">PacketOutputEvent</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/testing.html#PacketOutputEvent"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.testing.PacketOutputEvent" title="Permalink to this definition">¶</a></dt>
<dd><p>Test event that models a packet that should be emitted by
a router/switch.</p>
<dl class="method">
<dt id="switchyard.lib.testing.PacketOutputEvent.match">
<code class="descname">match</code><span class="sig-paren">(</span><em>evtype</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/testing.html#PacketOutputEvent.match"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.testing.PacketOutputEvent.match" title="Permalink to this definition">¶</a></dt>
<dd><p>Does event type match me?  PacketOutputEvent requires
two additional keyword args: device (str) and packet (packet object).</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="application-layer">
<h2>Application-layer<a class="headerlink" href="#application-layer" title="Permalink to this headline">¶</a></h2>
<p>Two static methods on the <code class="docutils literal"><span class="pre">ApplicationLayer</span></code> class are used to send messages up a socket application and to receive messages from socket applications.</p>
<dl class="class">
<dt id="switchyard.lib.socket.ApplicationLayer">
<em class="property">class </em><code class="descclassname">switchyard.lib.socket.</code><code class="descname">ApplicationLayer</code><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#ApplicationLayer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.ApplicationLayer" title="Permalink to this definition">¶</a></dt>
<dd><dl class="staticmethod">
<dt id="switchyard.lib.socket.ApplicationLayer.recv_from_app">
<em class="property">static </em><code class="descname">recv_from_app</code><span class="sig-paren">(</span><em>timeout=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#ApplicationLayer.recv_from_app"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.ApplicationLayer.recv_from_app" title="Permalink to this definition">¶</a></dt>
<dd><p>Called by a network stack implementer to receive application-layer
data for sending on to a remote location.</p>
<p>Can optionally take a timeout value.  If no data are available,
raises NoPackets exception.</p>
<p>Returns a 2-tuple: flowaddr and data.
The flowaddr consists of 5 items: protocol, localaddr, localport, 
remoteaddr, remoteport.</p>
</dd></dl>

<dl class="staticmethod">
<dt id="switchyard.lib.socket.ApplicationLayer.send_to_app">
<em class="property">static </em><code class="descname">send_to_app</code><span class="sig-paren">(</span><em>proto</em>, <em>local_addr</em>, <em>remote_addr</em>, <em>data</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#ApplicationLayer.send_to_app"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.ApplicationLayer.send_to_app" title="Permalink to this definition">¶</a></dt>
<dd><p>Called by a network stack implementer to push application-layer
data &#8220;up&#8221; from the stack.</p>
<p>Arguments are protocol number, local_addr (a 2-tuple of IP address
and port), remote_addr (a 2-tuple of IP address and port), and the
message.</p>
<p>Returns True if a socket was found to which to deliver the message,
and False otherwise.  When False is returned, a log warning is also
emitted.</p>
</dd></dl>

</dd></dl>

<p>Switchyard&#8217;s socket emulation module is intended to follow, relatively closely, the methods and attributes available in the built-in <code class="xref py py-mod docutils literal"><span class="pre">socket</span></code> module.</p>
<dl class="class">
<dt id="switchyard.lib.socket.socket">
<em class="property">class </em><code class="descclassname">switchyard.lib.socket.</code><code class="descname">socket</code><span class="sig-paren">(</span><em>family</em>, <em>socktype</em>, <em>proto=0</em>, <em>fileno=0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket" title="Permalink to this definition">¶</a></dt>
<dd><p>A socket object, emulated by Switchyard.</p>
<dl class="method">
<dt id="switchyard.lib.socket.socket.accept">
<code class="descname">accept</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.accept"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.accept" title="Permalink to this definition">¶</a></dt>
<dd><p>Not implemented.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.bind">
<code class="descname">bind</code><span class="sig-paren">(</span><em>address</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.bind"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.bind" title="Permalink to this definition">¶</a></dt>
<dd><p>Alter the local address with which this socket is associated.
The address parameter is a 2-tuple consisting of an IP address
and port number.</p>
<p>NB: this method fails and returns -1 if the requested port
to bind to is already in use but does <em>not</em> check that the
address is valid.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.close">
<code class="descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.close"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.close" title="Permalink to this definition">¶</a></dt>
<dd><p>Close the socket.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.connect">
<code class="descname">connect</code><span class="sig-paren">(</span><em>address</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.connect"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.connect" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the remote address (IP address and port) with which
this socket is used to communicate.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.connect_ex">
<code class="descname">connect_ex</code><span class="sig-paren">(</span><em>address</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.connect_ex"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.connect_ex" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the remote address (IP address and port) with which
this socket is used to communicate.</p>
</dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.socket.socket.family">
<code class="descname">family</code><a class="headerlink" href="#switchyard.lib.socket.socket.family" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the address family of the socket.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.getpeername">
<code class="descname">getpeername</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.getpeername"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.getpeername" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a 2-tuple containing the remote IP address and port
associated with the socket, if any.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.getsockname">
<code class="descname">getsockname</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.getsockname"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.getsockname" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a 2-tuple containing the local IP address and port
associated with the socket.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.getsockopt">
<code class="descname">getsockopt</code><span class="sig-paren">(</span><em>level</em>, <em>option</em>, <em>buffersize=0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.getsockopt"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.getsockopt" title="Permalink to this definition">¶</a></dt>
<dd><p>Not implemented.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.gettimeout">
<code class="descname">gettimeout</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.gettimeout"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.gettimeout" title="Permalink to this definition">¶</a></dt>
<dd><p>Obtain the currently set timeout value.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.listen">
<code class="descname">listen</code><span class="sig-paren">(</span><em>backlog</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.listen"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.listen" title="Permalink to this definition">¶</a></dt>
<dd><p>Not implemented.</p>
</dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.socket.socket.proto">
<code class="descname">proto</code><a class="headerlink" href="#switchyard.lib.socket.socket.proto" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the protocol of the socket.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.recv">
<code class="descname">recv</code><span class="sig-paren">(</span><em>buffersize</em>, <em>flags=0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.recv"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.recv" title="Permalink to this definition">¶</a></dt>
<dd><p>Receive data on the socket.  The buffersize and flags
arguments are currently ignored.  Only returns the data.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.recv_into">
<code class="descname">recv_into</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.recv_into"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.recv_into" title="Permalink to this definition">¶</a></dt>
<dd><p>Not implemented.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.recvfrom">
<code class="descname">recvfrom</code><span class="sig-paren">(</span><em>buffersize</em>, <em>flags=0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.recvfrom"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.recvfrom" title="Permalink to this definition">¶</a></dt>
<dd><p>Receive data on the socket.  The buffersize and flags
arguments are currently ignored.  Returns the data and
an address tuple (IP address and port) of the remote host.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.recvfrom_into">
<code class="descname">recvfrom_into</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.recvfrom_into"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.recvfrom_into" title="Permalink to this definition">¶</a></dt>
<dd><p>Not implemented.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.recvmsg">
<code class="descname">recvmsg</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.recvmsg"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.recvmsg" title="Permalink to this definition">¶</a></dt>
<dd><p>Not implemented.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.send">
<code class="descname">send</code><span class="sig-paren">(</span><em>data</em>, <em>flags=0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.send"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.send" title="Permalink to this definition">¶</a></dt>
<dd><p>Send data on the socket.  A call to connect() must have
been previously made for this call to succeed.
Flags is currently ignored.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.sendall">
<code class="descname">sendall</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.sendall"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.sendall" title="Permalink to this definition">¶</a></dt>
<dd><p>Not implemented.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.sendmsg">
<code class="descname">sendmsg</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.sendmsg"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.sendmsg" title="Permalink to this definition">¶</a></dt>
<dd><p>Not implemented.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.sendto">
<code class="descname">sendto</code><span class="sig-paren">(</span><em>data</em>, <em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.sendto"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.sendto" title="Permalink to this definition">¶</a></dt>
<dd><p>Send data on the socket.  Accepts the same parameters as the
built-in socket sendto: data[, flags], address
where address is a 2-tuple of IP address and port.
Any flags are currently ignored.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.setblocking">
<code class="descname">setblocking</code><span class="sig-paren">(</span><em>flags</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.setblocking"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.setblocking" title="Permalink to this definition">¶</a></dt>
<dd><p>Set whether this socket should block on a call to recv*.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.setsockopt">
<code class="descname">setsockopt</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.setsockopt"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.setsockopt" title="Permalink to this definition">¶</a></dt>
<dd><p>Not implemented.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.settimeout">
<code class="descname">settimeout</code><span class="sig-paren">(</span><em>timeout</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.settimeout"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.settimeout" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the timeout value for this socket.</p>
</dd></dl>

<dl class="method">
<dt id="switchyard.lib.socket.socket.shutdown">
<code class="descname">shutdown</code><span class="sig-paren">(</span><em>flag</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/socket/socketemu.html#socket.shutdown"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.socket.socket.shutdown" title="Permalink to this definition">¶</a></dt>
<dd><p>Shut down the socket.  This is currently implemented by
calling close().</p>
</dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.socket.socket.timeout">
<code class="descname">timeout</code><a class="headerlink" href="#switchyard.lib.socket.socket.timeout" title="Permalink to this definition">¶</a></dt>
<dd><p>Obtain the currently set timeout value.</p>
</dd></dl>

<dl class="attribute">
<dt id="switchyard.lib.socket.socket.type">
<code class="descname">type</code><a class="headerlink" href="#switchyard.lib.socket.socket.type" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the type of the socket.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="utility-functions">
<h2>Utility functions<a class="headerlink" href="#utility-functions" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="switchyard.lib.logging.log_failure">
<code class="descclassname">switchyard.lib.logging.</code><code class="descname">log_failure</code><span class="sig-paren">(</span><em>s</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/logging.html#log_failure"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.logging.log_failure" title="Permalink to this definition">¶</a></dt>
<dd><p>Convenience function for failure message.</p>
</dd></dl>

<dl class="function">
<dt id="switchyard.lib.logging.log_warn">
<code class="descclassname">switchyard.lib.logging.</code><code class="descname">log_warn</code><span class="sig-paren">(</span><em>s</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/logging.html#log_warn"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.logging.log_warn" title="Permalink to this definition">¶</a></dt>
<dd><p>Convenience function for warning message.</p>
</dd></dl>

<dl class="function">
<dt id="switchyard.lib.logging.log_info">
<code class="descclassname">switchyard.lib.logging.</code><code class="descname">log_info</code><span class="sig-paren">(</span><em>s</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/logging.html#log_info"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.logging.log_info" title="Permalink to this definition">¶</a></dt>
<dd><p>Convenience function for info message.</p>
</dd></dl>

<dl class="function">
<dt id="switchyard.lib.logging.log_debug">
<code class="descclassname">switchyard.lib.logging.</code><code class="descname">log_debug</code><span class="sig-paren">(</span><em>s</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/logging.html#log_debug"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.logging.log_debug" title="Permalink to this definition">¶</a></dt>
<dd><p>Convenience function for debugging message.</p>
</dd></dl>

<dl class="function">
<dt id="switchyard.lib.debugging.debugger">
<code class="descclassname">switchyard.lib.debugging.</code><code class="descname">debugger</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/switchyard/lib/debugging.html#debugger"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#switchyard.lib.debugging.debugger" title="Permalink to this definition">¶</a></dt>
<dd><p>Invoke the interactive debugger.  Can be used anywhere
within a Switchyard program.</p>
</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="release_notes.html" title="Release notes"
             >next</a> |</li>
        <li class="right" >
          <a href="installation.html" title="Installing Switchyard"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">Switchyard 2017.01.5 documentation</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2013-2017, Joel Sommers.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.1.
    </div>
  </body>
</html>